<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>我的课程</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }
        .navbar {
            background-color: #333;
            overflow: hidden;
            padding: 10px 20px;
        }
        .navbar a {
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 14px 20px;
            text-decoration: none;
        }
        .navbar a:hover {
            background-color: #ddd;
            color: black;
        }
        .container {
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            max-width: 900px;
            margin: 20px auto;
        }
        h2 {
            color: #333;
            text-align: center;
            margin-bottom: 25px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
            color: #333;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .message {
            margin-top: 15px;
            padding: 10px;
            border-radius: 4px;
            font-size: 14px;
            text-align: center;
        }
        .error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
        .success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
    </style>
</head>
<body>
    <div class="navbar">
        <a href="${pageContext.request.contextPath}/laoshi_index.jsp">首页</a>
        <a href="${pageContext.request.contextPath}/laoshi_publish_course.jsp">发布课程</a>
        <a href="${pageContext.request.contextPath}/laoshi_my_courses">我的课程</a>
        <a href="${pageContext.request.contextPath}/laoshi_personal_center">个人中心</a>
        <a href="${pageContext.request.contextPath}/logout">退出登录</a>
    </div>
    <div class="container">
        <h2>我发布的课程</h2>
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>课程名称</th>
                    <th>课程描述</th>
                    <th>最大容量</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach var="course" items="${myCourses}">
                    <tr>
                        <td><c:out value="${course.id}"/></td>
                        <td><c:out value="${course.courseName}"/></td>
                        <td><c:out value="${course.courseDescription}"/></td>
                        <td><c:out value="${course.maxCapacity}"/></td>
                        <td>
                            <!-- 可以在这里添加编辑或删除课程的按钮 -->
                            <button class="btn-edit" onclick="window.location.href = '${pageContext.request.contextPath}/laoshi_edit_course?id=${course.id}';">编辑</button>
                            <form action="${pageContext.request.contextPath}/laoshi_delete_course" method="post" style="display:inline;" onsubmit="return confirm('您确定要删除此课程吗？');">
                                <input type="hidden" name="courseId" value="${course.id}">
                                <button type="submit" class="btn-del">删除</button>
                            </form>
                            <form action="${pageContext.request.contextPath}/laoshi_end_course" method="post" style="display:inline; margin-left: 5px;" onsubmit="return confirm('您确定要结束此课程吗？此操作将永久删除课程及其所有相关选课记录。');">
                                <input type="hidden" name="courseId" value="${course.id}">
                                <button type="submit" class="btn-end">已结束</button>
                            </form>
                        </td>
                    </tr>
                </c:forEach>
                <c:if test="${empty myCourses}">
                    <tr>
                        <td colspan="5">您还没有发布任何课程。</td>
                    </tr>
                </c:if>
            </tbody>
        </table>

        <c:if test="${not empty errorMessage}">
            <p class="message error"><c:out value="${errorMessage}"/></p>
        </c:if>
        <c:if test="${not empty successMessage}">
            <p class="message success"><c:out value="${successMessage}"/></p>
        </c:if>
    </div>
</body>
</html> 